<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function swap(arr, i, j) {
        if (!Array.isArray(arr)) return; 
        if (i < 0 || j < 0) return;     
        if (i >= arr.length || j >= arr.length) return;
        
        [arr[i], arr[j]] = [arr[j], arr[i]];
    }

        let arrN =  [89, 78,37,110,56, 100, 21, 87, 77, 0, 52, 8, 151,25, 80,7];
        let arr =  [89, 78,37,110,56, 100, 21, 87, 77, 0, 52, 8, 151,25, 80,7];
        for(let i = 0;i <arr.length; i++){
            for(let j = 0; j<arr.length-i;j++){
                if(arr[j] < arr[j+1]){
                    swap(arr,j,j+1);
                }
            }
        }
        console.log(arr);
    

    let arr1 = arrN;
    for(let i=0;i < arr1.length ; i++){
        let index = i;
        for(let j=i+1;j < arr1.length;j++){
            if(arr1[j]>arr1[index]){
                index = j;
            }
        }
        swap(arr1,i,index);
    }
    console.log(arr1);


    let arr2 = arrN;
    for(let i=1; i<arr2.length;i++){
        let cur = arr2[i];
        for(let j= i-1;j>=0;j--){
           if(arr2[j] < cur){
                    arr2[j+1] = array[j];
                } else {
                    arr2[j+1] = cur;
                    break;
                }
        } 
    }
    console.log(arr2);
    
    </script>
    
</body>
</html>
